import request from '@/utils/request'
import longRequest from '@/utils/longRequest'
import qs from 'qs'

export function add(s) {
    return request({
        url: '/api/product/add.do',
        method: 'post',
        data: {
            product: s.product,
            labels: s.labels,
            params: s.params,
            productAttributes: s.productAttributes,
            productSkus: s.productSkus
        }
    })
}

export function list(index, pageSize, name, status, orderBy) {
    return request({
        url: '/api/product/list.do',
        method: 'get',
        params: {
            index, pageSize, name, status, orderBy
        }
    })
}

export function changeShow(id) {
    return request({
        url: '/api/product/changeStatus.do',
        method: 'get',
        params: {
            id
        }
    })
}

export function changeLabels(id, labelId) {
    return request({
        url: '/api/product/changeLabels.do',
        method: 'get',
        params: {
            id, labelId
        }
    })
}

export function findSku(id) {
    return request({
        url: '/api/product/findSku.do',
        method: 'get',
        params: {
            id
        }
    })
}

export function changeSkuStatus(id) {
    return request({
        url: '/api/product/changeSkuStatus.do',
        method: 'get',
        params: {
            skuId: id
        }
    })
}

export function updateSku(param) {
    return request({
        url: '/api/product/updateSku.do',
        method: 'post',
        data: {
            id: param.id,
            stock: param.stock,
            saleNum: param.saleNum,
            price: param.price,
            marketPrice: param.marketPrice,
            costPrice: param.costPrice,
            status: param.status
        }
    })
}

export function productParams(id) {
    return request({
        url: '/api/product/productParams.do',
        method: 'get',
        params: {
            id
        }
    })
}


export function updateParams(type,id,productId,name,value) {
    return request({
        url: '/api/product/updateParams.do',
        method: 'get',
        params: {
            type,
            id,
            productId,
            name,
            value
        }
    })
}


export function productDetail(id) {
    return request({
        url: '/api/product/productDetail.do',
        method: 'get',
        params: {
            id
        }
    })
}


export function updateDetail(id,detail) {
    return request({
        url: '/api/product/updateDetail.do',
        method: 'post',
        data: qs.stringify({
            id,
            detail
        })
    })
}


export function detail(id) {
    return request({
        url: '/api/product/detail.do',
        method: 'get',
        params: {
            id
        }
    })
}

export function getCrawlDetail(url) {
    return longRequest({
        url: '/api/product/getCrawlDetail.do',
        method: 'get',
        params: {
            url
        }
    })
}

export function updateName(id,name) {
    return request({
        url: '/api/product/updateName.do',
        method: 'get',
        params: {
            id,
            name
        }
    })
}


